package com.jeasonzhao.report.model.simpledb;

import com.jeasonzhao.model.Model;
import com.jeasonzhao.model.ModelException;
import com.jeasonzhao.model.ModelField;
import com.jeasonzhao.model.ModelHelper;
import com.jeasonzhao.report.model.ReportDict;

/**
 * Create table SQLRPT_DICT
 * (
 * 	id varchar(64) not null primary key not null,
 * 	name varchar(255) not null,
 * 	parentId varchar(64) null,
 * 	xmlContent text not null
 * );
 **/
@Model("dict")
public class DbDict
{
    @ModelField
    private String id = null;
    @ModelField
    private String name = null;
    @ModelField
    private String parentId = null;
    @ModelField
    private String xmlContent = null;
    public ReportDict toStandardObject()
        throws ModelException
    {
        ReportDict dict = ModelHelper.getInstance().fromXML(ReportDict.class,this.xmlContent);
        if(null == dict)
        {
            return null;
        }
        else
        {
            dict.setId(this.id);
            dict.setName(this.name);
            dict.setParentId(this.parentId);
            return dict;
        }
    }

    public static DbDict fromStandardObject(ReportDict dict)
        throws ModelException
    {
        if(null == dict)
        {
            return null;
        }
        else
        {
            DbDict db = new DbDict();
            db.id = dict.getId();
            db.name = dict.getName();
            db.parentId = dict.getParentId();
            db.xmlContent = ModelHelper.getInstance().toXML(dict).toString();
            return db;
        }
    }
}
